package day18.edu;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

// Created: 19/09/2025, ChangJiang Ru
public class ProductTest {
    public static void main(String[] args)
    {
        Product[] arr = new Product[5];
        arr[0] = new Product("Huawei", 6999);
        arr[1] = new Product("Vivo", 4999);
        arr[2] = new Product("Oppo", 4999);
        arr[3] = new Product("Apple", 9999);
        arr[4] = new Product("Xiaomi", 6999);



        for (int i = 0; i < 5; i++) {
            System.out.println(arr[i]);
        }

        Comparator comparator1 = new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof Product && o2 instanceof Product)
                {
                    Product p1 = (Product)o1;
                    Product p2 = (Product)o2;
                    return ((Product) o1).getName().compareTo(((Product) o2).getName());
                }

                throw new RuntimeException("Type is match error");
            }
        };

        Arrays.sort(arr,comparator1);
    }

    @Test
    public void test1()
    {
        Product p1 = new Product("Huawei", 4999);
        Product p2 = new Product("Vivo", 4999);
        int value = p1.compareTo(p2);
        System.out.println(value);
    }
}
